﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ScrumTime.Models.Task>" %>


<script>




    //    $(function () {
    //        //$("#catalog").accordion();
    //        //        $("#sortable").sortable({
    //        //            revert: true
    //        //        });

    //        $("#div-tasks ol").droppable({
    //            activeClass: "ui-state-default",
    //            hoverClass: "ui-state-hover",
    //            accept: ":not(.ui-sortable-helper)",
    //            drop: function (event, ui) {
    //                $(this).find(".placeholder").remove();
    //                //$("<li></li>").text(ui.draggable.text()).appendTo(this);
    //                $("<li></li>").text(ui.draggable.text()).appendTo(this);
    //            }
    //        }).sortable({
    //            items: "li:not(.placeholder)",
    //            sort: function () {
    //                // gets added unintentionally by droppable interacting with sortable
    //                // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
    //                $(this).removeClass("ui-state-default");
    //            }
    //        });
    //    });


        function getLiOfOl( nameOfOl) {
            var testlist = [];

            $('#ol-task-uaffectedtask li').each(function () {
                testlist.push($(this).attr('affectedTaskId'));
            });

            // alert( testlist.join("-") );
            return testlist.join("-");
        }


        function showStory_save_task() {
            var storyId = $('#showStory_Task_StoryId').val();
            var taskId = $('#showStory_Task_TaskId').val();

            var description = $('#showStoryTask-description').val();
            var hours = $('#showStoryTask-hours').val();

            var v_usabilityAffected_task = getLiOfOl();

                $.post('/Task/Save',
                {
                    storyId: storyId, taskId: taskId,
                    description: description, hours: hours, usabilityaffectedtasks: v_usabilityAffected_task
                },
                function (data) {
                    if (verificarError(data)) return;
                    LoadTasks();
                }
            );
        }

        function ShowStoryTaskSave() {
            showStory_save_task(); 
            return true;
        }

        function ShowStoryTaskCancel(){
            LoadTasks();
            return true;
        }

        function LoadTasks() {
            var storyid = $("#show-story-basicdata-idStory").val();
            $.post('/Story/ShowStory_Tasks',
                {
                    id: storyid
                },
                function (data) {
                    if (verificarError(data)) return;
                    $("#div_main_show_story_taskList").html(data);
                }
            );

        }

</script>
<input type="hidden" id="showStory_Task_TaskId" />
<input type="hidden" id="showStory_Task_StoryId" />
<table style="width:100%;">
    <tr>
        <td>
            <table>
                <tr>
                    <td>
                        id:
                    </td>
                    <td>
                        <input type="text" id="showStoryTask-id"  disabled="disabled" />
                    </td>
                </tr>
                <tr>
                    <td>
                        description:
                    </td>
                    <td>
                        <textarea id="showStoryTask-description" rows="3" cols="50"><%: Model.Description %></textarea>
                    </td>
                </tr>
                <tr>
                    <td>
                        hours: 
                    </td>
                    <td>
                        <input  id="showStoryTask-hours"type="text"  />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <div id="div-info-task-uaffectedtask" style="border-width:1px;">
                <span>Usability Affected Tasks</span>
                    <ol id="ol-task-uaffectedtask">
			            <%
                            foreach (ScrumTime.Models.UsabilityAffectedTask uat in Model.UsabilityAffectedTasks) { 
                            %>
                                <li id="li_at_<%:uat.UsabilityAffectedTaskId%>"  affectedTaskId="<%:uat.UsabilityAffectedTaskId%>" > <%:uat.Description%> <a href="#" onclick="remove_li_af(<%:uat.UsabilityAffectedTaskId%>)">&lt;remove&gt;</a> </li>
                            <%
                            }
                        %>
		            </ol>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <button id="show-story-task-button-edit" onclick="ShowStoryTaskSave();">Save</button>
            <button id="show-story-task-button-cancel"  onclick="ShowStoryTaskCancel();">Cancel</button>
        </td>    
    </tr>

</table>

<script>
    
         $("#show-story-task-button-edit").button();
         $("#show-story-task-button-cancel").button();
         // set values
         $("#showStory_Task_TaskId").val('<%:Model.TaskId %>');
         $("#showStory_Task_StoryId").val('<%:Model.StoryId %>');
         $("#showStoryTask-id").val('<%:Model.TaskId %>');
         
         $("#showStoryTask-hours").val('<%: Model.Hours%>');
    
</script>